<template>
    <div >
        <div style="height: 20px;"/>
        <div class="block"><el-avatar :size="70" :src="ico"></el-avatar></div><br/>
        <el-tag :type="powerT">{{ powerN }}</el-tag><br/><br/>
        <p>{{ userName }}</p>
        <el-link @click="exit" type="warning">退出登录</el-link>
    </div>
</template>

<script>
    export default {
        name: "userHead",
        created: function f() {
            this.$axios
                .get('/api/user/getMsg')
                .then((req)=>{
                    const tmp = req.data.data;
                    console.log(tmp);
                    // 若有头像信息，装载 ico
                    if(tmp.ico){
                        this.ico = tmp.ico;
                        localStorage.setItem('ico',this.ico);
                    }
                    this.userName = tmp.name;
                    localStorage.setItem('userName',tmp.name);
                    const power = parseInt(tmp.power);
                    this.powerT = this.powerType[power];
                    this.powerN = this.powerName[power];
                })
        },
        data() {
            return {
                powerType: ["info", "success", "warning", "danger"],
                powerName: ["未认证用户", "认证用户", "管理员", "封禁用户"],
                powerT: "info",
                powerN: "",
                userName: "",
                ico:
                    "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
            };
        },
        methods:{
            applySuccess:function(){
                this.$axios.post("/api/user/update",{
                    power:"00"
                })
                .then(req=>{
                    this.$message.success("已交由管理员审核");
                })
            },
            exit:function () {
                localStorage.removeItem('token');
                this.$router.push('/');
            }
        }
    }
</script>

<style scoped>

</style>
